﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HustQQClient.UI
{
    public partial class LabelTextbox : UserControl
    {
        string content = "";
        public string Content
        {
            get { return content; }
            set { content = value;}
        }

        string blankContent = "";
        public string BlankContent
        {
            get { return blankContent; }
            set { blankContent = value; }
        }
        
        int state = 0;

        public LabelTextbox()
        {
            InitializeComponent();
            label1.Click += new EventHandler(label1_Click);
            DisplayContent();
        }

        public void DisplayContent()       //显示文字
        {
            textBox1.Visible = false;
            label1.Visible = true;
            label1.Text = content;
            label1.Text = content == "" ? blankContent : content;
            state = 0;
        }

        public void EditContent()          //编辑文字
        {
            textBox1.Visible = true;
            label1.Visible = false;
            textBox1.Text = content;
            textBox1.Focus();
            state = 1;
        }

        public void SaveContent()          //保存并显示文字
        {
            content = textBox1.Text;
            DisplayContent();
        }

        void label1_Click(object sender, EventArgs e)
        {
            EditContent();
        }

        private void LabelTextbox_Click(object sender, EventArgs e)
        {
            EditContent();
        }

        private void LabelTextbox_Leave(object sender, EventArgs e)
        {
            if (state == 1)
                SaveContent();
        }
    }
}
